﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
		<c:set var="ctx" value="${pageContext.request.contextPath}" />
		<html>

		<head>
			<link rel="stylesheet" href="${ctx}/common/common.css">
			<meta charset="utf-8">
			<title>工艺管理编辑</title>
			<meta name="renderer" content="webkit">
			<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
			<meta name="viewport"
				content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
			<link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
			<link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/modules/layer/default/layer.css"
				media="all">
			<link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
			<script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>

			<style>
				.layui-table-header {
					width: 100%;
				}

				.layui-table-header th {
					width: 20%;
					text-align: center;
				}

				.layui-products {
					border-bottom: 2px solid #e7e7e7;
					/*border-top: 2px solid #e7e7e7;*/
					margin: 10px 0px;
					padding: 5px 0px;
				}

				.layui-products_li {
					margin-left: 50px;
					border-bottom: 1px dashed #e7e7e7;
				}

				.layui-products_li:first-child {
					border: none;
				}

				.layui-col-md4 img {
					margin-right: 5px;
					width: 22px;
					height: 22px;
				}

				.layui-col-md4 img {
					margin-right: 5px;
					width: 22px;
					height: 22px;
				}

				.valtop {
					padding: 9px
				}

				.layui-layer-dialog {
					position: fixed;
					top: 217px !important;
					left: 50% !important;
					margin-left: -130px !important
				}

				.layui-unselect.layui-form-select {
					width: 100%;
				}
			</style>
		</head>

		<body style="height: 100%">
			<!--主体内容层-->
			<form class="layui-form layui-col-md12" action="${ctx}/process/processEditSave">
				<div class="layui-fluid">
					<button type="button" id="rollback" class="layui-btn layui-btn-primary goback">返回</button>
					<div class="layui-row layui-col-space15">
						<input type="hidden" id="processId" name="processId" value="${proess.id }">
						<input type="hidden" id="delIds" name="delIds">
						<!--输入框内容盒子-->
						<div class="layui-col-md12">
							<div class="layui-form-item layui-col-md6">
								<label class="layui-form-label">工艺代码：</label>
								<div class="layui-input-block valtop">${proess.code }</div>
							</div>
							<div class=" layui-col-md6">
								<label class="layui-form-label">工艺名称：</label>
								<div class="layui-input-block valtop">${proess.name }</div>
							</div>
						</div>
					</div>
					<div id="addCard" class="layui-card-body" style="padding: 10px 0px; border-top: 1px solid #e7e7e7;">
						<c:forEach items="${proess.tTechnicIndexList }" var="technic">
							<div class="layui-row" style="border-bottom: 1px dashed #e7e7e7;">
								<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">
									<div class="layui-col-md1 valtop" style="display: flex;justify-content: center;">
										<input type="hidden" name="technicId" value="${technic.id }">
										<img class="delDiv" src="${ctx}/common/plugins/images/u.png">
									</div>
									<div class="layui-col-md4 valtop">
										<span style="display: inline-block; float: left;">指标代码<span
												style="color: red">*</span>：</span>
										<div class="layui-input-block">
											<input type="text" name="code" value="${technic.code }" required
												lay-verify="required" placeholder="指标代码" autocomplete="off"
												class="layui-input">
										</div>
									</div>
									<div class="layui-col-md7 valtop">
										<span style="display: inline-block; float: left;">采集方式<span
												style="color: red">*</span>：</span>
										<div class="layui-input-block">
											<select name="gatherMethod">
												<c:forEach items="${gatherMethod }" var="obj">
													<c:choose>
														<c:when test="${technic.gather_method == obj.code}">
															<option value="${obj.code }" selected="selected">
																${obj.described }</option>
														</c:when>
														<c:otherwise>
															<option value="${obj.code }">${obj.described }</option>
														</c:otherwise>
													</c:choose>
												</c:forEach>
											</select>
										</div>
									</div>
								</div>
								<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">
									<div class="layui-col-md1 valtop">
									</div>
									<div class="layui-col-md4 valtop">
										<span style="display: inline-block; float: left;">指标名称<span
												style="color: red">*</span>：</span>
										<div class="layui-input-block">
											<input type="text" name="name" value="${technic.name }" required
												lay-verify="required" placeholder="指标名称" autocomplete="off"
												class="layui-input">
										</div>
									</div>
									<div class="layui-col-md7 valtop">
										<span style="display: inline-block; float: left;">是否公开<span
												style="color: red">*</span>：</span>
										<div class="layui-input-block">
											<select name="shareStat">
												<c:choose>
													<c:when test="${technic.share_stat == 1}">
														<option value="0">否</option>
														<option value="1" selected="selected">是</option>
													</c:when>
													<c:otherwise>
														<option value="0" selected="selected">否</option>
														<option value="1">是</option>
													</c:otherwise>
												</c:choose>
											</select>
										</div>
									</div>
								</div>
								<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">
									<div class="layui-col-md1 valtop">
									</div>
									<div class="layui-col-md4 valtop">
										<span style="display: inline-block; float: left;">指标单位：</span>
										<div class="layui-input-block">
											<input type="text" name="unit" value="${technic.unit }" placeholder="指标单位"
												autocomplete="off" class="layui-input">
										</div>
									</div>
									<div class="layui-col-md7 valtop">
										<span style="display: inline-block; float: left;">是否必填<span
												style="color: red">*</span>：</span>
										<div class="layui-input-block">
											<select name="isInput">
												<c:choose>
													<c:when test="${technic.isInput == 1}">
														<option value="0">否</option>
														<option value="1" selected="selected">是</option>
													</c:when>
													<c:otherwise>
														<option value="0" selected="selected">否</option>
														<option value="1">是</option>
													</c:otherwise>
												</c:choose>
											</select>
										</div>
									</div>
								</div>
								<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">
									<div class="layui-col-md1 valtop">
									</div>
									<div class="layui-col-md4 valtop">
										<span style="display: inline-block; float: left;">采集类型<span
												style="color: red">*</span>：</span>
										<div class="layui-input-block">
											<select name="quotaType">
												<c:forEach items="${gatherTypeList }" var="gatherType">
													<c:choose>
														<c:when test="${gatherType.code == technic.quota_type}">
															<option value="${gatherType.code }" selected="selected">
																${gatherType.described }</option>
														</c:when>
														<c:otherwise>
															<option value="${gatherType.code }">
																${gatherType.described }</option>
														</c:otherwise>
													</c:choose>
												</c:forEach>
											</select>
										</div>
									</div>
									<div class="layui-col-md7 valtop">
										<span style="display: inline-block; float: left;">描述：</span>
										<div class="layui-input-block">
											<textarea name="described" placeholder="请输入描述"
												class="layui-textarea">${technic.described }</textarea>
										</div>
									</div>
								</div>
							</div>
						</c:forEach>
					</div>
					<!--通用按钮盒子-->
					<div class="layui-col-md12">
						<div style="text-align: center;">
							<div class="layui-btn" id="addTechnic">添加工艺指标</div>
							<button class="layui-btn" id="formBtn" lay-submit lay-filter="formDemo">保存</button>
						</div>
					</div>
				</div>
			</form>
			<script type="text/javascript">
				layui.use(['form'], function () {
					var $ = layui.$;
					var form = layui.form;
					document.getElementById("addTechnic").addEventListener("click", function () {
						str = '';
						str += '<div class="layui-row" style="border-bottom: 1px dashed #e7e7e7;">';
						str += '<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">';
						str += '	<div class="layui-col-md1 valtop" style="display: flex;justify-content: center;">';
						str += '		<input type="hidden" name="technicId" value="newId">';
						str += '		<img class="delDiv" src="${ctx}/common/plugins/images/u.png">';
						str += '	</div>';
						str += '	<div class="layui-col-md4 valtop">';
						str += '		<span style="display: inline-block; float: left;">指标代码<span style="color: red">*</span>：</span>';
						str += '	<div class="layui-input-block">';
						str += '		<input type="text" name="code" required lay-verify="required" placeholder="指标代码" autocomplete="off" class="layui-input">';
						str += '	</div>';
						str += '	</div>';
						str += '	<div class="layui-col-md7 valtop">';
						str += '		<span style="display: inline-block; float: left;">采集方式<span style="color: red">*</span>：</span>';
						str += '	<div class="layui-input-block">';
						str += '		<select name="gatherMethod">';
						str += '			<c:forEach items="${gatherMethod }" var="obj">';
						str += '				<option value="${obj.code }">${obj.described }</option>';
						str += '			</c:forEach>';
						str += '		</select>';
						str += '	</div>';
						str += '	</div>';
						str += '</div>';
						str += '<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">';
						str += '	<div class="layui-col-md1 valtop"></div>';
						str += '	<div class="layui-col-md4 valtop">';
						str += '		<span style="display: inline-block; float: left;">指标名称<span style="color: red">*</span>：</span>';
						str += '	<div class="layui-input-block">';
						str += '		<input type="text" name="name" required lay-verify="required" placeholder="指标名称" autocomplete="off" class="layui-input">';
						str += '	</div>';
						str += '	</div>';
						str += '	<div class="layui-col-md7 valtop">';
						str += '		<span style="display: inline-block; float: left;">是否公开<span style="color: red">*</span>：</span>';
						str += '	<div class="layui-input-block">';
						str += '		<select name="shareStat">';
						str += '			<option value="0">否</option>';
						str += '			<option value="1">是</option>';
						str += '		</select>';
						str += '	</div>';
						str += '	</div>';
						str += '</div>';
						str += '<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">';
						str += '	<div class="layui-col-md1 valtop"></div>';
						str += '	<div class="layui-col-md4 valtop">';
						str += '		<span style="display: inline-block; float: left;">指标单位：</span>';
						str += '	<div class="layui-input-block">';
						str += '		<input type="text" name="unit" placeholder="指标单位" autocomplete="off" class="layui-input">';
						str += '	</div>';
						str += '	</div>';
						str += '	<div class="layui-col-md7 valtop">';
						str += '		<span style="display: inline-block; float: left;">是否必填<span style="color: red">*</span>：</span>';
						str += '		<div class="layui-input-block">';
						str += '		<select name="isInput">';
						str += '			<option value="0">否</option>';
						str += '			<option value="1">是</option>';
						str += '		</select>';
						str += '	</div>';
						str += '	</div>';
						str += '</div>';
						str += '<div class="layui-row layui-col-space12 layui-products_li" style="border: none;">';
						str += '	<div class="layui-col-md1 valtop">';
						str += '	</div>';
						str += '	<div class="layui-col-md4 valtop">';
						str += '		<span style="display: inline-block; float: left;">采集类型<span style="color: red">*</span>：</span>';
						str += '		<div class="layui-input-block">';
						str += '		<select name="quotaType">';
						str += '			<c:forEach items="${gatherTypeList }" var="gatherType">';
						str += '				<option value="${gatherType.code }">${gatherType.described }</option>';
						str += '			</c:forEach>';
						str += '		</select>';
						str += '	</div>';
						str += '	</div>';
						str += '	<div class="layui-col-md7 valtop">';
						str += '		<span style="display: inline-block; float: left;">描述：</span>';
						str += '	<div class="layui-input-block">';
						str += '		<textarea name="described" placeholder="请输入描述" class="layui-textarea"></textarea>	';
						str += '	</div>';
						str += '	</div>';
						str += '</div>';
						str += '</div>';
						$('#addCard').append(str);
						form.render('select'); //刷新select选择框渲染
					});

					var delIds = '';
					$(document).on("click", ".delDiv", function () {
						var obj = this;
						layer.confirm('确认删除？', function (index) {
							layer.close(index);
							var delId = $(obj).prev("input").val();
							console.log(delId);
							if (delId != null && delId != 'undefined' && delId != 'newId') {
								delIds += delId + ",";
							}
							$(obj).parent().parent().parent().remove();
							$('#delIds').val(delIds);
						})
						/* if(delId == undefined || delId == ''){
							layer.confirm('确认删除?', function (index) {
								$(this).parent().parent().parent().remove();
							})
						}else{
							layer.confirm('确认删除?', function (index) {
								layer.close(index);
								$.post("${ctx}/process/deleteTechnic", {delId: delId}, function (data) {
									if (data == '1') {
										layer.alert("删除成功");
										$(this).parent().parent().parent().remove();
									} else {
										layer.alert("删除失败");
									}
								}, "text")
							})
						} */
					});
				});

				layui.use('form', function () {
					var form = layui.form;
					/* 监听提交 */
					form.on('submit(formDemo)', function (data) {
						var Obtn = document.getElementsByClassName("delDiv");
						if (Obtn.length == 0) {
							alert("请添加工艺指标");
							return false;
						}
						layer.load(1, {
							shade: [0.1, '#fff'] //0.1透明度的白色背景
						});
						$("#formBtn").attr("disabled", true);
					});
				})
				document.getElementById("rollback").addEventListener("click", function () {
					window.history.back();
				})
			</script>
		</body>

		</html>